<template>
	<view class="news">
		

		<div class="searchbox">
			<div class="bgi">
				<image class="pic" src="/static/14.png" alt=""/>
				<uv-navbar bgColor='transparent' :placeholder='true'  :fixed='false'>
					<template v-slot:left>
						<view class="title"></view>
					</template>
					<template v-slot:center>
						<view class="title">科普</view>
					</template>
				</uv-navbar>
			<!-- 	<div class="search">
					<image class="icon" src="/static/search.png" mode=""></image>
					<input class="text" type="text" @confirm='confirm' confirm-type='search' placeholder="搜索资讯关键词">
				</div> -->
			</div>	
		</div>
		

		
		<div class="list_box" >
			<div class="item" @click='toDetail(item.id)' v-for="(item,index) in listData.list" :key="index">
				<image class="pic"  :src="item.image" mode=""></image>
				<div class="desc">{{item.title}}</div>
			</div>
			<div class="more_bar" @click='lookMore'>{{tips}}</div>
		</div>
	</view>
</template>

<script>
	import { getnewList } from '@/network/api.js'
	import { baseURL } from '@/network/config.js'
	export default {
		data() {
			return {
				listData:{
					total:0,
					list:[]
				},
				baseURL,
				query:{ page:1,limit:10},
				tips:'查看更多'
			}
		},
		onLoad(options){
			this.getIndexnewsList(this.query)
			
		},
		methods: {
			
			navTo(path){uni.navigateTo({url: path});},
			async getList(newTypeId){
				// const { data } = await getnewList({newTypeId})
				const { data } = await getnewList()
				console.log(data)
				this.data = data
			},
			
			async getIndexnewsList(query){
				const {data} = await getnewList(query)
				console.log('res:',data)
				const list = data.list.map(i=>({...i, image:`${baseURL}${i.image}`}))
				data.list = list
				if(list.length==0){
					// uni.showToast({title: '没有更多了',duration: 2000,icon:'none'});
					this.tips = '没有更多了'
					this.query.page --
				}
				this.listData.list = [...this.listData.list,...data.list]
			},
			lookMore(){
				this.query.page ++
				this.getIndexnewsList(this.query)
			},
			
			
			
			
			
			
			
			toDetail(id){
				uni.navigateTo({
					url:`/pages/chidai_detail/chidai_detail?id=${id}`
				})
			},
			async confirm(e){
				console.log('val:',e.detail.value)
				const { data } = await getnewList({keywords:e.detail.value})
				console.log(data)
				this.data = data
			},
	
		}
	}
</script>

<style scoped lang="less">
	.title {
		display: flex;
		align-items: center;
		font-weight: bold;
	}

	.bgi {
		position: relative;
		top: 0;
		left: 0;
		right: 0;
		background-color: #ccc;
		z-index: 99;
		overflow: hidden;
		.pic{
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			width: 100%;
			height: 100%;
			z-index: -99;
		}
	}

	.search {
		height: 70rpx;
		background-color: #fff;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		flex: 1;
		padding: 0 30rpx;
		margin: 10rpx 25rpx 25rpx 25rpx;
		.icon {
			width: 35rpx;
			height: 35rpx;
			margin-right: 10rpx;
		}

		.text {
			flex: 1;
			font-size: 25rpx;
			font-weight: 400;
			color: #898989;
		}
	}

	.list_box{
		margin :0 25rpx 20rpx 25rpx;
		.item{
			display: flex;
			padding: 33rpx 0;
			border-bottom:1px solid #EAEAEA;
			&:last-child{
				border:none;
			}
			.pic{
				width: 340rpx;
				height: 210rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				flex-shrink: 0;
			}
			.desc{
				font-size: 28rpx;
				font-weight: 400;
				color: #444444;
				line-height: 50rpx;
				flex:1;
				margin: 18rpx 0 0 25rpx;
			}
		}
	}
	.more_bar{
		font-size: 24rpx;
		font-weight: 400;
		color: #BDBDBD;
		padding: 30rpx 0;
		text-align: center;
	}
</style>